<template>
    <el-container class="home-container">
        <!-- 头部 -->
        <el-header>
            <div>
                <img src="../assets/logo.jpg" alt="">
                <span>电商后台管理系统</span>
            </div> 
            <el-button type="info" @click="logout">退出</el-button>
        </el-header>
        <!-- 主体 -->
        <el-container>
            <!-- 侧边栏 -->
            <el-aside :width="isCollapse?'64px':'200px'">
                <div class="toggle-button" @click="toggleCollapse">
                    |||
                </div>
                <el-menu
                background-color="#282828"
                text-color="#989898"
                active-text-color="#489EFF"
                unique-opened
                :collapse="isCollapse"
                :collapse-transition="false"
                router
                >
                <!-- 一级菜单 -->
                <el-submenu :index="item.id+''" v-for="item in menuList" :key="item.id">
                    <!-- 一级菜单模版区域 -->
                    <template slot="title">
                        <!-- 图标 -->
                        <i :class="iconsObj[item.id]"></i>
                        <!-- 文本 -->
                        <span>{{item.authName}}</span>
                    </template>
                    <!-- 二级菜单 -->
                    <el-menu-item :index="'/'+subItem.path" v-for="subItem in item.children" :key="subItem.id">
                        <template slot="title">
                        <!-- 图标 -->
                        <i class="el-icon-menu"></i>
                        <!-- 文本 -->
                        <span>{{subItem.authName}}</span>
                    </template>
                    </el-menu-item>
                    
                </el-submenu>
                
                </el-menu>
            </el-aside>
            <!-- 右侧 -->
            <el-main>
                <router-view></router-view>
            </el-main>
        </el-container>
    </el-container>
    
</template>
<script>
export default {
    data(){
        return{
            //是否折叠
            isCollapse:false,
            menuList:[],
            iconsObj:{
                '125':'iconfont icon-user',
                '103':'iconfont icon-tijikongjian',
                '101':'iconfont icon-shangpin',
                '102':'iconfont icon-danju',
                '145':'iconfont icon-baobiao'
            }
        }
    },
    created(){
        this.getMenuList()
    },
    methods:{
        logout(){
            window.sessionStorage.clear();
            this.$router.push("/login")
        },
        async getMenuList(){
            const {data:res}=await this.$axios.get('menus')
            console.log(res);
            if(res.meta.status!==200)return this.$message.error(res.meta.msg)
            this.menuList=res.data
        },
        //切换菜单的折叠与展开
        toggleCollapse(){
            this.isCollapse=!this.isCollapse
        }
    }
    
    
}
</script>
<style lang="scss" scoped>
.home-container{
    height: 100%;
}
.el-header{
    background-color: #428ee4;
    display: flex;
    height: 100px;
    justify-content: space-between;
    align-items: center;
    padding-left: 0;
    color: #fdfefb;
    font-size: 20px;
    div{
        display: flex;
        align-items: center;
        span{
            margin-left: 15px;
        }
    }
    img{
        width: 100px;
        height: 60px;
    }
}
.el-aside{
    background-color: #282828;
    color: #989898;
    .el-menu{
        border-right: none;
    }
}
.el-container{
    background-color: #f2f2f2;
}
.iconfont{
    margin-right: 10px;;
}
.toggle-button{
    background-color: #282828;
    color: #989898;
    font-size: 10px;
    line-height: 24px;
    text-align: center;
    letter-spacing: .4em;
    cursor: pointer;
}
</style>